<template>
  <div class="content">
    <el-row class="row-bg" :gutter="20">
      <el-col :span="14">
        <div class="grid-content bg-purple">
          <h2 class="title">请选择你感兴趣的内容</h2>
          <div class="cards">
            <!-- <el-card class="card" v-for="item in interest" :key="item.id">
              <div>
                {{ item.name }}
              </div>
            </el-card> -->
            <el-checkbox-group
              v-model="types"
              @change="handleCheckedChange"
              class="radio-group"
            >
              <div class="radio-item" v-for="item in interest" :key="item.name">
                <el-checkbox :label="item.id" border>{{
                  item.name
                }}</el-checkbox>
              </div>
            </el-checkbox-group>
          </div>
        </div>
      </el-col>
      <el-col :span="10"></el-col>
    </el-row>
    <div>
      <el-button @click="submit" type="primary" plain>确认</el-button>
      <el-button @click="jump">跳过</el-button>
    </div>
  </div>
</template>

<script>
import api from "@api/index";
import { getId } from "@/utils/auth";
export default {
  data() {
    return {
      interest: [],
      types: [],
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      api.getType().then(
        (res) => {
          console.log(res);
          this.interest = res.data;
        },
        (err) => {
          console.log(err);
        }
      );
    },
    jump() {
      this.$router.push({ path: "/index" });
    },
    submit() {
      var data = {
        id: getId(),
        type: this.types.toString(),
      };
      api.selectType(data).then(
        (res) => {
          console.log(res);
          if (res.code === 200) {
            this.$notify({
              title: res.msg,
              type: "success",
              duration: 6000,
            });
            this.$router.push({ path: "/index" });
          } else {
            this.$notify({
              title: res.msg,
              type: "error",
              duration: 6000,
            });
          }
        },
        (err) => {
          console.log(err);
        }
      );
    },
    handleCheckedChange(value) {
      console.log(value.toString());
      console.log(this.types);
    },
  },
};
</script>

<style scoped>
.content {
  min-height: 100vh;
  background-image: url(../assets/images/bg1.jpg);
  background-size: cover;
  background-position: center center;
}
.bg-purple {
  /* background: #d3dce6; */
  margin: 40px;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.cards {
  margin: 40px;
  display: flex;
  flex-wrap: wrap;
}
.card {
  margin-right: 10px;
  margin-bottom: 10px;
  width: 30%;
  height: 100px;
  /* background-image: url(../assets/images/bg2.jpg);
  background-size: cover;
  background-position: center center;
  color: aliceblue; */
  font-size: 40px;
  font-weight: 700;
}
.el-card__body,
.el-main {
  padding: 0px;
}
.img {
  width: 100%;
  height: 100%;
}
.radio-group {
  display: flex;
  flex-wrap: wrap;
}
.radio-item {
  width: 31%;
  margin-right: 10px;
  margin-bottom: 5px;
}
</style>